import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:flutter_first_one/get_controller/count.dart';

class Me extends StatefulWidget {
  const Me({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _MeState createState() => _MeState();
}

class _MeState extends State<Me> {
  // 实例化全局状态对象，Get.put会马上实例化，而且只能实例化一次，这种写法不好
  // CountController countController = Get.put(CountController());
  // get.find 找到全局状态对象
  CountController countController = Get.find<CountController>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('儿时故事'),
      ),
      body: Column(
        children: [
          Obx(() => Text(countController.count.toString())),
          ElevatedButton(
            onPressed: () {
              countController.add();
            },
            child: Text('++'),
          )
        ],
      ),
    );
  }
}
